home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / dev / asm / ESA.lha / ESA / examples / sss / code / misc.ei < prev    next >
Encoding:
Text File  |  1999-10-14  |  6.7 KB  |  235 lines

  1. *******************************************************************************
  2. * Init v1.1.2
  3. *******************************************************************************
  4. * INFO    execute some system inits
  5. * SYN    success = Init[CmdLnPtr,CmdLnLen]
  6. *    d0      a0       d0.w
  7. * IN    CmdLnPtr    ptr to the shell command line string
  8. *    CmdLnLen    length in chars of the command line
  9. * OUT    success    0=ERROR
  10. * MOD    _DOSBase    dos.library ptr
  11. *    _StdOut    standard output filehandle
  12. *    CmdLn    command line (NULL-terminated) string
  13. * REQ    _DOSName    address of "dos.library",0
  14. * NOTE    this code could be improved by using GetArgStr() or ReadArgs()
  15. *    for standard OS command line parsing
  16. *******************************************************************************
  17.  
  18.     function Init[a0/d0.w],d1/d7/a0-a1/a6:d0.l
  19.  
  20.     moveq.l    #0,d7
  21.  
  22.     subq.w    #1,d0    ;don't copy closing RETURN
  23.     lea.l    CmdLn,a1    ;dest buf
  24.     when.s    {#512ยป=d0.w} & d0.w
  25.      subq.w    #1,d0    ;"expire" = "dbra"
  26.      expire d0=d0
  27.       move.b    (a0)+,(a1)+    ;copy command line
  28.       addq.l    #1,d7
  29.      nexp
  30.     ewhen
  31.     clr.b    (a1)    ;NULL-terminated
  32.  
  33.     movea.l    4.w,a6
  34.     lea.l    _DOSName,a1
  35.     moveq.l    #37,d0    ;at least KS 2.04
  36.     jsr    (_LVOOpenLibrary,a6)
  37.     move.l    d0,_DOSBase
  38.  
  39.     when.s d0
  40.      movea.l    d0,a6
  41.      jsr    (_LVOOutPut,a6)
  42.      move.l    d0,_StdOut    ;still true (~0)
  43.     ewhen
  44.  
  45.     efunc
  46.  
  47. *******************************************************************************
  48. * CleanUp v1.0.3
  49. *******************************************************************************
  50. * INFO    frees allocated system resources
  51. * SYN    CleanUp[]
  52. * REQ    _DOSBase    dos.library ptr
  53. *******************************************************************************
  54.  
  55.     procedure CleanUp[],d0-d1/a0-a1/a6
  56.  
  57.     move.l    InFileHnd,d1    ;source file handle
  58.     when.s d1.l
  59.      movea.l    _DOSBase,a6
  60.      jsr    (_LVOClose,a6)
  61.     ewhen
  62.  
  63.     move.l    WrkBufLen,d0    ;free allocated buf
  64.     when.s d0.l
  65.      movea.l    4.w,a6
  66.      movea.l    WrkBufAdr,a1
  67.      jsr    (_LVOFreeMem,a6)
  68.     ewhen
  69.  
  70.     movea.l    _DOSBase,a1
  71.     movea.l    4.w,a6
  72.     jsr    (_LVOCloseLibrary,a6)
  73.  
  74.     moveq.l    #0,d0    ;retcode
  75.     eproc
  76.  
  77. *******************************************************************************
  78. * Print v1.0.0
  79. *******************************************************************************
  80. * INFO    prints a text to the standard output if quiet mode is OFF
  81. * SYN    Print[TxtPtr]
  82. *          d2
  83. * IN    TxtPtr    ptr to NULL-terminated text string
  84. * REQ    _DOSBase    dos.library ptr
  85. *    _StdOut    standard output handle
  86. *******************************************************************************
  87.  
  88.     procedure Print[d2],d0-d3/a0-a1/a6
  89.  
  90.     move.b    flags,d0
  91.     andi.b    #1<<F_QUIETMODE,d0
  92.  
  93.     when.s ~d0.b        ;if quiet mode OFF
  94.      movea.l    d2,a0
  95. .findend     tst.b    (a0)+
  96.      bne.s    .findend    ;find end of string
  97.      move.l    a0,d3
  98.      sub.l    d2,d3    ;length
  99.      movea.l    _DOSBase,a6
  100.      move.l    _StdOut,d1
  101.      jsr    (_LVOWrite,a6)
  102.     ewhen
  103.  
  104.     eproc
  105.  
  106. *******************************************************************************
  107. * ShowResult v1.1.1
  108. *******************************************************************************
  109. * INFO    prints out the texts associated to a given errcode
  110. * SYN    ShowResult[ErrCode]
  111. *               d0
  112. * IN    ErrCode    0=OK, else E_xxxxxx (see defs.i)
  113. *******************************************************************************
  114.  
  115.     procedure ShowResult[d0]
  116.     when.s d0
  117.      Print[#txt_error]    ;"ERROR: "
  118.     ewhen
  119.     Print[(ErrTab.l,d0.l*4)]    ;print msg
  120.     eproc
  121.  
  122. *******************************************************************************
  123. * SkipSpaces v1.0.0
  124. *******************************************************************************
  125. * INFO    starting from the current position in a string, returns the
  126. *    position of the 1st character different from ' '
  127. * SYN    SkipSpaces[StrPtr]
  128. *               a0
  129. * IN    StrPtr    ptr to a string
  130. * MOD    a0.l    position of the 1st char <>' '
  131. *******************************************************************************
  132.  
  133.     procedure SkipSpaces[a0]
  134. .find    cmpi.b    #' ',(a0)+
  135.     beq.s    .find
  136.     subq.l    #1,a0
  137.     eproc
  138.  
  139. *******************************************************************************
  140. * Valu v1.0.2
  141. *******************************************************************************
  142. * INFO    converts a decimal ASCII string to an unsigned long integer
  143. * SYN    IntVal = Valu[StrPtr]
  144. *    d0    a0
  145. * IN    StrPtr    ptr to numerical string
  146. * OUT    IntVal    unsigned integer
  147. * MOD    a0.l    ptr after string
  148. * NOTE    it stops at the 1st char not inside ['0'...'9']
  149. *******************************************************************************
  150.  
  151.     function Valu[a0],d1-d2:d0
  152.     moveq.l    #0,d0
  153.     moveq.l    #0,d1
  154.     do
  155.      move.b    (a0)+,d1    ;get a digit (d)
  156.      subi.b    #'0',d1    ;convert to int
  157.      bcs.s    .exit    ;if d<0...
  158.      cmpi.b    #9,d1
  159.      bhi.s    .exit    ;if d>9...
  160.      move.l    d0,d2    ;IntVal
  161.      add.l    d0,d0    ;2*IntVal
  162.      lsl.l    #3,d2    ;8*IntVal
  163.      add.l    d2,d0    ;10*IntVal
  164.      add.l    d1,d0    ;10*IntVal+d -> IntVal
  165.     loop
  166. .exit
  167.     efunc
  168.  
  169. *******************************************************************************
  170. * Stru v1.0.0
  171. *******************************************************************************
  172. * INFO    converts an unsigned long integer to a NULL-terminated, decimal
  173. *    ASCII string
  174. * SYN    Stru[Int,Dest,Len]
  175. *         d0  a0   d1
  176. * IN    Int    integer to convert
  177. *    Dest    ptr to destination buffer
  178. *    Len    the string will be exactly Len chars long
  179. *        (MUST be >0!!!)
  180. * NOTE    the destination buffer MUST be at least Len+1 bytes long!
  181. *******************************************************************************
  182.  
  183.     procedure    Stru[d0/a0/d1],d0-d2/a0
  184.     adda.l    d1,a0    ;last digit adr+1
  185.     clr.b    (a0)    ;final BLANK
  186.     subq.l    #1,d1
  187.     expire d1=d1
  188.      divul.l    #10,d2:d0    ;last digit
  189.      addi.b    #'0',d2    ;convert to ASCII
  190.      move.b    d2,-(a0)    ;store
  191.     nexp
  192.     eproc
  193.  
  194. *******************************************************************************
  195. * GetFileSize v1.0.1
  196. *******************************************************************************
  197. * INFO    returns the size in bytes of a file
  198. * SYN    Size=GetFileSize[Hnd]
  199. *    d0    d1
  200. * IN    Hnd    filehandle
  201. * OUT    d0    0 on failure
  202. * REQ    _DOSName    address of "dos.library",0
  203. * NOTE    uses TmpBuf (must be on a 4 bytes boundary)
  204. *******************************************************************************
  205.  
  206.     function GetFileSize[d1],d1-d2/a0-a1/a6:d0
  207.     move.l    #TmpBuf,d2
  208.     movea.l    _DOSBase,a6
  209.     jsr    (_LVOExamineFH,a6)
  210.     when.s d0.l
  211.      lea.l    TmpBuf,a0
  212.      move.l    (fib_Size,a0),d0
  213.     ewhen
  214.     efunc
  215.  
  216. *******************************************************************************
  217. * ChkBrk v1.0.0
  218. *******************************************************************************
  219. * INFO    checks if the user is pressing CTRL-C
  220. * SYN    ErrCode=ChkBrk[]
  221. *    d0
  222. * OUT    ErrCode    E_USRBRK if pressed, 0 otherwise
  223. *******************************************************************************
  224.  
  225.     function ChkBrk[],d1/a0-a1/a6:d0
  226.     movea.l    4.w,a6
  227.     moveq.l    #0,d0
  228.     move.l    #SIGBREAKF_CTRL_C,d1    ;chk & clr this signal
  229.     jsr    (-306,a6)    ;SetSignal()
  230.     btst.l    #SIGBREAKB_CTRL_C,d0    ;if the signal bit
  231.     sne.b    d0    ;was ON, then return
  232.     andi.b    #E_USRBRK,d0    ;the appropriate ErrCode
  233.     extb.l    d0
  234.     efunc
  235.